package com.yunxiang.dao.impl;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.yunxiang.dao.RedpackDao;
import com.yunxiang.domain.Redpack;

public class RedpackDaoImpl implements RedpackDao {

	public Redpack selectByPrimaryKey(int key) {
		String resource = "mybatis-config.xml";
		Redpack redpack = null;
		SqlSession sqlSession = null;
		try {
			InputStream is = Resources.getResourceAsStream(resource);
			SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
			sqlSession = sessionFactory.openSession();
			redpack = sqlSession.selectOne("com.yunxiang.domain.Redpack.selectByPrimaryKey", 411);
			return redpack;
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		return redpack;
	}

}
